//
//  TeachingViewController.m
//  LiangYa_BObject
//
//  Created by dllo on 15/10/28.
//  Copyright © 2015年 YuHao. All rights reserved.
//

#import "TeachingViewController.h"
#import "AppDelegate.h"
#import "SelectedCollectionViewCell.h"
#import "RoomCollectionViewCell.h"
#import "BookCollectionViewCell.h"
#import "BashCollectionViewCell.h"
#import "LiveCollectionViewCell.h"
#import "CookCollectionViewCell.h"
#import "TeachingData.h"
#import "TeachingWebViewController.h"
#import "CollectHandler.h"

@interface TeachingViewController()<UICollectionViewDataSource ,UICollectionViewDelegate,UIScrollViewDelegate>{
    MBProgressHUD *HUD;

}
@property (nonatomic, strong) UICollectionView *collectionview;
@property (nonatomic, strong) UIButton *button1;
@property (nonatomic, strong) UIButton *button2;
@property (nonatomic, strong) UIButton *button3;
@property (nonatomic, strong) UIButton *button4;
@property (nonatomic, strong) UIButton *button5;
@property (nonatomic, strong) UIButton *button6;
@property (nonatomic, strong) UIView *view1;
@property (nonatomic, strong) NSMutableArray *selectArr;
@property (nonatomic, strong) NSMutableArray *roomArr;
@property (nonatomic, strong) NSMutableArray *bookArr;
@property (nonatomic, strong) NSMutableArray *bashArr;
@property (nonatomic, strong) NSMutableArray *liveArr;
@property (nonatomic, strong) NSMutableArray *cookArr;
@property (nonatomic, strong) NSMutableArray *selectMoreArr;
@property (nonatomic, strong) NSMutableArray *roomMoreArr;
@property (nonatomic, strong) NSMutableArray *bookMoreArr;
@property (nonatomic, strong) NSMutableArray *bashMoreArr;
@property (nonatomic, strong) NSMutableArray *liveMoreArr;
@property (nonatomic, strong) NSMutableArray *cookMoreArr;
@property (nonatomic, strong) SelectedCollectionViewCell *selectCell;
@property (nonatomic, strong) RoomCollectionViewCell *roomCell;
@property (nonatomic, strong) BookCollectionViewCell *bookCell;
@property (nonatomic, strong) BashCollectionViewCell *bashCell;
@property (nonatomic, strong) LiveCollectionViewCell *liveCell;
@property (nonatomic, strong) CookCollectionViewCell *cookCell;
@property (nonatomic, strong) UIButton *highlightB;


@end

@implementation TeachingViewController
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"创意";
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
        self.view.backgroundColor = [UIColor colorWithRed:57/255.0 green:57/255.0 blue:57/255.0 alpha:1];
    }else{
        self.view.backgroundColor = [UIColor whiteColor];
    }
    
    
    
    UIButton *menuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    menuBtn.frame = CGRectMake(0, 0, 20, 18);
    [menuBtn setBackgroundImage:[UIImage imageNamed:@"drawer"] forState:UIControlStateNormal];
    [menuBtn addTarget:self action:@selector(leftAction) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:menuBtn];

    [self SelectedHandlData];
    [self RoomHandlData];
    [self BookHandlData];
    [self BashHandlData];
    [self LiveHandlData];
    [self CookHandlData];
    
    
    self.button1 = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button1.frame = CGRectMake(0,64 , ScreenWidth/6, 40);
    [self.button1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.button1 setTitle:@"精选" forState:UIControlStateNormal];
    [self.button1 addTarget:self action:@selector(buttonAction1:) forControlEvents:UIControlEventTouchUpInside];
     [self.view addSubview:self.button1];
    self.highlightB = _button1;
    
    self.button2 = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button2.frame = CGRectMake(ScreenWidth/6,64 , ScreenWidth/6, 40);
    [self.view addSubview:self.button2];
//    [self.button2 setTitleColor:[UIColor blackColor] forState:normal];
    [self.button2 addTarget:self action:@selector(buttonAction2:) forControlEvents:UIControlEventTouchUpInside];
    [self.button2 setTitle:@"卧室" forState:UIControlStateNormal];
    
    self.button3 = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button3.frame = CGRectMake(ScreenWidth*2/6, 64 , ScreenWidth/6, 40);
    [self.view addSubview:self.button3];
//    [self.button3 setTitleColor:[UIColor blackColor] forState:normal];
    [self.button3 addTarget:self action:@selector(buttonAction3:) forControlEvents:UIControlEventTouchUpInside];
    [self.button3 setTitle:@"书房" forState:UIControlStateNormal];
    
    self.button4 = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button4.frame = CGRectMake(ScreenWidth*3/6,64 , ScreenWidth/6, 40);
//    [self.button4 setTitleColor:[UIColor blackColor] forState:normal];
    [self.button4 addTarget:self action:@selector(buttonAction4:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.button4];
    [self.button4 setTitle:@"卫浴" forState:UIControlStateNormal];
    
    self.button5 = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button5.frame = CGRectMake(ScreenWidth*4/6,64 , ScreenWidth/6, 40);
    [self.view addSubview:self.button5];
//    [self.button5 setTitleColor:[UIColor blackColor] forState:normal];
    [self.button5 addTarget:self action:@selector(buttonAction5:) forControlEvents:UIControlEventTouchUpInside];
    [self.button5 setTitle:@"客厅" forState:UIControlStateNormal];
    
    self.button6 = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button6.frame = CGRectMake(ScreenWidth*5/6, 64 , ScreenWidth/6, 40);
    [self.view addSubview:self.button6];
//    [self.button6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.button6 addTarget:self action:@selector(buttonAction6:) forControlEvents:UIControlEventTouchUpInside];
    [self.button6 setTitle:@"厨房" forState:UIControlStateNormal];
    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
        [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }else{
        [self.button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button4 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button5 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button6 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    
    
    self.view1 = [[UIView alloc] init];
    self.view1.frame = CGRectMake(0, 104, ScreenWidth/6, 2);
    [self.view addSubview:self.view1];
    self.view1.backgroundColor = [UIColor redColor];

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(ScreenWidth, Screenheight );
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 0;
  
    
    self.collectionview = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 106, ScreenWidth, Screenheight) collectionViewLayout:flowLayout];
    self.collectionview.backgroundColor = [UIColor whiteColor];
    self.collectionview.delegate = self;
    self.collectionview.dataSource = self;
    [self.view addSubview:self.collectionview];
    self.collectionview.pagingEnabled = YES;
    _collectionview.backgroundColor = [UIColor clearColor];

    
    [self.collectionview registerClass:[SelectedCollectionViewCell class] forCellWithReuseIdentifier:@"haha"];
    [self.collectionview registerClass:[RoomCollectionViewCell class] forCellWithReuseIdentifier:@"haha1"];
    [self.collectionview registerClass:[BookCollectionViewCell class] forCellWithReuseIdentifier:@"haha2"];
    [self.collectionview registerClass:[LiveCollectionViewCell class] forCellWithReuseIdentifier:@"haha3"];
    [self.collectionview registerClass:[BashCollectionViewCell class] forCellWithReuseIdentifier:@"haha4"];
    [self.collectionview registerClass:[CookCollectionViewCell class] forCellWithReuseIdentifier:@"haha5"];
    
    
    
    HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  HUD.labelText = @"数据加载中...";
    
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(nightAction:) name:@"night" object:nil];
}

- (void)nightAction:(NSNotification *)sender
{
    self.view.backgroundColor = [sender.userInfo objectForKey:@"backcolor"];
    [self.button1 setTitleColor:[sender.userInfo objectForKey:@"textcolor"] forState:UIControlStateNormal];
    [self.button2 setTitleColor:[sender.userInfo objectForKey:@"textcolor"] forState:UIControlStateNormal];
    [self.button3 setTitleColor:[sender.userInfo objectForKey:@"textcolor"] forState:UIControlStateNormal];
    [self.button4 setTitleColor:[sender.userInfo objectForKey:@"textcolor"] forState:UIControlStateNormal];
    [self.button5 setTitleColor:[sender.userInfo objectForKey:@"textcolor"] forState:UIControlStateNormal];
    [self.button6 setTitleColor:[sender.userInfo objectForKey:@"textcolor"] forState:UIControlStateNormal];
    [self.highlightB setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//    NSLog(@"%f",scrollView.contentOffset.x);
    if (scrollView.contentOffset.x == 0) {
        [self.button1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        self.highlightB = _button1;
        if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
            [self.button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button4 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button5 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button6 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }else{
        [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }
    }else if (scrollView.contentOffset.x == ScreenWidth){

        [self.button2 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        self.highlightB = _button2;
        if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
            [self.button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button4 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button5 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button6 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }else{
            [self.button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }

    }else if (scrollView.contentOffset.x == ScreenWidth * 2){

        [self.button3 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        self.highlightB = _button3;
        if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
            [self.button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button4 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button5 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button6 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }else{
            [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }

    }else if (scrollView.contentOffset.x == ScreenWidth* 3 ){

        [self.button4 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        self.highlightB = _button4;
        if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
            [self.button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button5 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button6 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }else{
            [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }

    }else if (scrollView.contentOffset.x  == ScreenWidth * 4){

        [self.button5 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        self.highlightB = _button5;
        if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
            [self.button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button4 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button6 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }else{
            [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }

    }else if(scrollView.contentOffset.x == ScreenWidth * 5 ){

        [self.button6 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        self.highlightB = _button6;
        if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
            [self.button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button4 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button5 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [self.button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }else{
            [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [self.button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }

    }
    self.view1.frame = CGRectMake(scrollView.contentOffset.x/6 ,104, ScreenWidth/6, 2);
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        self.selectCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"haha" forIndexPath:indexPath];
        self.selectCell.dataArray = self.selectArr;
        [self.selectCell.tabelView reloadData];
        self.selectCell.tabelView.showsVerticalScrollIndicator = NO;

        //      下拉刷新
        MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(SelectedHandlData)];
        self.selectCell.tabelView.header = header;

        // 上拉加载
        MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            [self SelectedHandlMoreData:self.selectCell];
        }];
        self.selectCell.tabelView.footer = footer;
        
        void (^block) (TeachingData *str) = ^(TeachingData *str){
            TeachingWebViewController *webVC = [[TeachingWebViewController alloc] init];
            webVC.teachingData = str;
            [self.navigationController pushViewController:webVC animated:YES];
//            [self presentViewController:webVC animated:YES completion:^{
//                
//            }];
            
        
        };
        
        self.selectCell.block = block;

        return self.selectCell;
    }else if (indexPath.row == 1){
        self.roomCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"haha1" forIndexPath:indexPath];
        self.roomCell.dataArray = self.roomArr;
        [self.roomCell.tabelView reloadData];
        self.roomCell.tabelView.showsVerticalScrollIndicator = NO;

        //      下拉刷新
        MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(RoomHandlData)];
        self.roomCell.tabelView.header = header;

        // 上拉加载
        MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            [self RoomHandlMoreData:self.roomCell];
        }];
        self.roomCell.tabelView.footer = footer;
        void (^block) (TeachingData *str) = ^(TeachingData *str){
            TeachingWebViewController *webVC = [[TeachingWebViewController alloc] init];
            webVC.teachingData = str;
            [self.navigationController pushViewController:webVC animated:YES];
            //            [self presentViewController:webVC animated:YES completion:^{
            //
            //            }];

        };
        
        self.roomCell.block = block;

        return self.roomCell;
    }else if (indexPath.row == 2){
        self.bookCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"haha2" forIndexPath:indexPath];
        self.bookCell.dataArray = self.bookArr;
        [self.bookCell.tabelView reloadData];
        self.bookCell.tabelView.showsVerticalScrollIndicator = NO;

        //      下拉刷新
        MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(BookHandlData)];
        self.bookCell.tabelView.header = header;

        // 上拉加载
        MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            [self BookHandlMoreData:self.bookCell];
        }];
        self.bookCell.tabelView.footer = footer;
        
        void (^block) (TeachingData *str) = ^(TeachingData *str){
            TeachingWebViewController *webVC = [[TeachingWebViewController alloc] init];
            webVC.teachingData = str;
            [self.navigationController pushViewController:webVC animated:YES];
            //            [self presentViewController:webVC animated:YES completion:^{
            //
            //            }];

        };
        
        self.bookCell.block = block;

        return self.bookCell;
    }else if (indexPath.row == 3){
        self.bashCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"haha4" forIndexPath:indexPath];
        _bashCell.dataArray = self.bashArr;
        [_bashCell.tabelView reloadData];
        self.bashCell.tabelView.showsVerticalScrollIndicator = NO;

        
//      下拉刷新
        MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(BashHandlData)];
        _bashCell.tabelView.header = header;
        
//      上拉加载
        MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            [self BashHandlMoreData:_bashCell];
        }];
        _bashCell.tabelView.footer = footer;
        
        void (^block) (TeachingData *str) = ^(TeachingData *str){
            TeachingWebViewController *webVC = [[TeachingWebViewController alloc] init];
            webVC.teachingData = str;
            [self.navigationController pushViewController:webVC animated:YES];
            //            [self presentViewController:webVC animated:YES completion:^{
            //
            //            }];
        };
        
        _bashCell.block = block;

        return _bashCell;
    }else if (indexPath.row == 4){
        self.liveCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"haha3" forIndexPath:indexPath];
        self.liveCell.dataArray = self.liveArr;
        [self.liveCell.tabelView reloadData];
        self.liveCell.tabelView.showsVerticalScrollIndicator = NO;

        //      下拉刷新
        MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(LiveHandlData)];
        self.liveCell.tabelView.header = header;

        // 上拉加载
        MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            [self LiveHandlMoreData:self.liveCell];
            [self.liveCell.tabelView reloadData];
        }];
        self.liveCell.tabelView.footer = footer;
        
        void (^block) (TeachingData *str) = ^(TeachingData *str){
            TeachingWebViewController *webVC = [[TeachingWebViewController alloc] init];
            webVC.teachingData = str;
            [self.navigationController pushViewController:webVC animated:YES];
            //            [self presentViewController:webVC animated:YES completion:^{
            //
            //            }];

        };
        
        self.liveCell.block = block;

        return self.liveCell;
    }else{
        self.cookCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"haha5" forIndexPath:indexPath];
        self.cookCell.dataArray = self.cookArr;
        [self.cookCell.tabelView reloadData];
        self.cookCell.tabelView.showsVerticalScrollIndicator = NO;

        //      下拉刷新
        MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(CookHandlData)];
        self.cookCell.tabelView.header = header;

        // 上拉加载
        MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            [self CookHandlMoreData:self.cookCell];
        }];
        self.cookCell.tabelView.footer = footer;
        
        void (^block) (TeachingData *str) = ^(TeachingData *str){
            TeachingWebViewController *webVC = [[TeachingWebViewController alloc] init];
            webVC.teachingData = str;
            [self.navigationController pushViewController:webVC animated:YES];
            //            [self presentViewController:webVC animated:YES completion:^{
            //
            //            }];
        };
        
        self.cookCell.block = block;

        return self.cookCell;
    }
}

- (void)buttonAction1:(UIButton *)btn
{
    self.collectionview.contentOffset = CGPointMake(0, 0);
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    self.highlightB = btn;
    
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
        [self.button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button4 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button5 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button6 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }else{
        [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }

}
- (void)buttonAction2:(UIButton *)btn
{
    self.highlightB = btn;
    self.collectionview.contentOffset = CGPointMake(ScreenWidth, 0);
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
        [self.button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button4 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button5 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button6 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }else{
        [self.button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }

}
- (void)buttonAction3:(UIButton *)btn
{
    self.highlightB = btn;
    self.collectionview.contentOffset = CGPointMake(ScreenWidth*2, 0);
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
        [self.button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button4 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button5 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button6 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }else{
        [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }

    
    
    
}
- (void)buttonAction4:(UIButton *)btn
{
    self.collectionview.contentOffset = CGPointMake(ScreenWidth*3, 0);
    self.highlightB = btn;
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
        [self.button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button5 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button6 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }else{
        [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }

}
- (void)buttonAction5:(UIButton *)btn
{
    self.highlightB = btn;
    self.collectionview.contentOffset = CGPointMake(ScreenWidth*4, 0);
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
        [self.button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button4 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button6 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }else{
        [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button6 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }

}
- (void)buttonAction6:(UIButton *)btn
{
    self.highlightB = btn;
    self.collectionview.contentOffset = CGPointMake(ScreenWidth*5, 0);
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
        [self.button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button4 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button5 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.button1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }else{
        [self.button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button5 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }

}

#pragma mark 处理精选数据
- (void)SelectedHandlData
{
    
    self.selectArr = [NSMutableArray array];
    self.selectMoreArr = [NSMutableArray array];
    NSString *str = @"http://api.bohejiaju.com/v2/channels/4/items?limit=20&offset=0&gender=1&generation=1";
    [AFRequdstAndLoad dataURLStr:str datahand:^(id object) {
        [HUD removeFromSuperview];
        NSDictionary *dic = [object objectForKey:@"data"];
        NSDictionary *dic2 = [dic objectForKey:@"paging"];
        NSString *next_url = [dic2 objectForKey:@"next_url"];
        [self.selectMoreArr addObject:next_url];
        NSArray *arr = [dic objectForKey:@"items"];
        for (NSDictionary *dic1 in arr) {
            TeachingData *selectData = [[TeachingData alloc] init];
            [selectData setValuesForKeysWithDictionary:dic1];
            [self.selectArr addObject:selectData];
        }
        [self.selectCell.tabelView.header endRefreshing];
       [self.collectionview reloadData];
    }];
}

- (void)SelectedHandlMoreData:(SelectedCollectionViewCell *)cell
{
    NSString *next_url = [self.selectMoreArr lastObject];
    if ([next_url isKindOfClass:[NSNull class]]) {
        [cell.tabelView.footer endRefreshing];
    }else{
        [AFRequdstAndLoad dataURLStr:next_url datahand:^(id object) {
            if (object) {
                [cell.tabelView.footer endRefreshing];
            }
            NSDictionary *dic = [object objectForKey:@"data"];
            NSDictionary *dic2 = [dic objectForKey:@"paging"];
            NSString *next_url = [dic2 objectForKey:@"next_url"];
            
            [self.selectMoreArr addObject:next_url];
            NSArray *arr = [dic objectForKey:@"items"];
            for (NSDictionary *dic1 in arr) {
                TeachingData *selectData = [[TeachingData alloc] init];
                [selectData setValuesForKeysWithDictionary:dic1];
                [self.selectArr addObject:selectData];
            }
            [self.collectionview reloadData];
            
        }];
    }
}


#pragma mark 处理卧室数据
- (void)RoomHandlData{
    self.roomArr = [NSMutableArray array];
    self.roomMoreArr = [NSMutableArray array];
    NSString *str = @"http://api.bohejiaju.com/v2/channels/13/items?limit=20&offset=0&gender=1&generation=1";
    [AFRequdstAndLoad dataURLStr:str datahand:^(id object) {
        NSDictionary *dic = [object objectForKey:@"data"];
        NSDictionary *dic2 = [dic objectForKey:@"paging"];
        NSString *next_url = [dic2 objectForKey:@"next_url"];
        [self.roomMoreArr addObject:next_url];
        NSArray *arr = [dic objectForKey:@"items"];
        for (NSDictionary *dic1 in arr) {
            TeachingData *selectData = [[TeachingData alloc] init];
            [selectData setValuesForKeysWithDictionary:dic1];
            [self.roomArr addObject:selectData];
        }
        [self.roomCell.tabelView.header endRefreshing];
        [self.collectionview reloadData];
    }];
}

- (void)RoomHandlMoreData:(RoomCollectionViewCell *)cell
{
    NSString *next_url = [self.roomMoreArr lastObject];
    if ([next_url isKindOfClass:[NSNull class]]) {
        [cell.tabelView.footer endRefreshing];
    }else{
        [AFRequdstAndLoad dataURLStr:next_url datahand:^(id object) {
            if (object) {
                [cell.tabelView.footer endRefreshing];
            }
            NSDictionary *dic = [object objectForKey:@"data"];
            NSDictionary *dic2 = [dic objectForKey:@"paging"];
            NSString *next_url = [dic2 objectForKey:@"next_url"];
            
            [self.roomMoreArr addObject:next_url];
            NSArray *arr = [dic objectForKey:@"items"];
            for (NSDictionary *dic1 in arr) {
                TeachingData *selectData = [[TeachingData alloc] init];
                [selectData setValuesForKeysWithDictionary:dic1];
                [self.roomArr addObject:selectData];
            }
            [self.collectionview reloadData];
            
        }];
    }
}


#pragma mark 处理书房数据
- (void)BookHandlData{
    self.bookArr = [NSMutableArray array];
    self.bookMoreArr = [NSMutableArray array];
    NSString *str = @"http://api.bohejiaju.com/v2/channels/16/items?limit=20&offset=0&gender=1&generation=1";
    [AFRequdstAndLoad dataURLStr:str datahand:^(id object) {
        
        NSDictionary *dic = [object objectForKey:@"data"];
        NSDictionary *dic2 = [dic objectForKey:@"paging"];
        NSString *next_url = [dic2 objectForKey:@"next_url"];
        [self.bookMoreArr addObject:next_url];

        NSArray *arr = [dic objectForKey:@"items"];
        for (NSDictionary *dic1 in arr) {
            TeachingData *selectData = [[TeachingData alloc] init];
            [selectData setValuesForKeysWithDictionary:dic1];
            [self.bookArr addObject:selectData];
        }
        [self.bookCell.tabelView.header endRefreshing];

        [self.collectionview reloadData];
    }];
}

- (void)BookHandlMoreData:(BookCollectionViewCell *)cell
{
    NSString *next_url = [self.bookMoreArr lastObject];
    if ([next_url isKindOfClass:[NSNull class]]) {
        [cell.tabelView.footer endRefreshing];
    }else{
        [AFRequdstAndLoad dataURLStr:next_url datahand:^(id object) {
            if (object) {
                [cell.tabelView.footer endRefreshing];
            }
            NSDictionary *dic = [object objectForKey:@"data"];
            NSDictionary *dic2 = [dic objectForKey:@"paging"];
            NSString *next_url = [dic2 objectForKey:@"next_url"];
            
            [self.bookMoreArr addObject:next_url];
            NSArray *arr = [dic objectForKey:@"items"];
            for (NSDictionary *dic1 in arr) {
                TeachingData *selectData = [[TeachingData alloc] init];
                [selectData setValuesForKeysWithDictionary:dic1];
                [self.bookArr addObject:selectData];
            }
            [self.collectionview reloadData];
            
        }];
    }
}


#pragma mark 处理卫浴数据
- (void)BashHandlData
{
    self.bashArr = [NSMutableArray array];
    self.bashMoreArr = [NSMutableArray array];
    NSString *str = @"http://api.bohejiaju.com/v2/channels/14/items?limit=20&offset=0&gender=1&generation=1";
    [AFRequdstAndLoad dataURLStr:str datahand:^(id object) {

        NSDictionary *dic = [object objectForKey:@"data"];
        NSDictionary *dic2 = [dic objectForKey:@"paging"];
        NSString *next_url = [dic2 objectForKey:@"next_url"];
        [self.bashMoreArr addObject:next_url];
        NSArray *arr = [dic objectForKey:@"items"];
        for (NSDictionary *dic1 in arr) {
            TeachingData *selectData = [[TeachingData alloc] init];
            [selectData setValuesForKeysWithDictionary:dic1];
            [self.bashArr addObject:selectData];
        }
        [self.bashCell.tabelView.header endRefreshing];
        [self.collectionview reloadData];
    }];
}

- (void)BashHandlMoreData:(BashCollectionViewCell *)cell
{
    NSString *next_url = [self.bashMoreArr lastObject];
    if ([next_url isKindOfClass:[NSNull class]]) {
        [cell.tabelView.footer endRefreshing];
    }else{
        [AFRequdstAndLoad dataURLStr:next_url datahand:^(id object) {
            if (object) {
                NSLog(@"sdasdasd");
            }
            NSDictionary *dic = [object objectForKey:@"data"];
            NSDictionary *dic2 = [dic objectForKey:@"paging"];
            NSString *next_url = [dic2 objectForKey:@"next_url"];
            [self.bashMoreArr addObject:next_url];
            NSArray *arr = [dic objectForKey:@"items"];
            for (NSDictionary *dic1 in arr) {
                TeachingData *selectData = [[TeachingData alloc] init];
                [selectData setValuesForKeysWithDictionary:dic1];
                [self.bashArr addObject:selectData];
            }
            [self.collectionview reloadData];
            
        }];
    }
}

#pragma mark 处理客厅数据
- (void)LiveHandlData{
    self.liveArr = [NSMutableArray array];
    self.liveMoreArr = [NSMutableArray array];
    NSString *str = @"http://api.bohejiaju.com/v2/channels/15/items?limit=20&offset=0&gender=1&generation=1";
    [AFRequdstAndLoad dataURLStr:str datahand:^(id object) {
        NSDictionary *dic = [object objectForKey:@"data"];
        NSDictionary *dic2 = [dic objectForKey:@"paging"];
        NSString *next_url = [dic2 objectForKey:@"next_url"];
        [self.liveMoreArr addObject:next_url];
        NSArray *arr = [dic objectForKey:@"items"];
        for (NSDictionary *dic1 in arr) {
            TeachingData *selectData = [[TeachingData alloc] init];
            [selectData setValuesForKeysWithDictionary:dic1];
            [self.liveArr addObject:selectData];
        }
        [self.liveCell.tabelView.header endRefreshing];
        [self.collectionview reloadData];
    }];
}

- (void)LiveHandlMoreData:(LiveCollectionViewCell *)cell
{
    NSString *next_url = [self.liveMoreArr lastObject];
    if ([next_url isKindOfClass:[NSNull class]]) {
        [cell.tabelView.footer endRefreshing];
    }else{
        [AFRequdstAndLoad dataURLStr:next_url datahand:^(id object) {
            if (object) {
                [cell.tabelView.footer endRefreshing];
            }
            NSDictionary *dic = [object objectForKey:@"data"];
            NSDictionary *dic2 = [dic objectForKey:@"paging"];
            NSString *next_url = [dic2 objectForKey:@"next_url"];
            
            [self.liveMoreArr addObject:next_url];
            NSArray *arr = [dic objectForKey:@"items"];
            for (NSDictionary *dic1 in arr) {
                TeachingData *selectData = [[TeachingData alloc] init];
                [selectData setValuesForKeysWithDictionary:dic1];
                [self.liveArr addObject:selectData];
            }
            
            [self.collectionview reloadData];
            
        }];
    }
}

#pragma mark 处理厨房数据
- (void)CookHandlData{

    NSString *str = @"http://api.bohejiaju.com/v2/channels/12/items?limit=20&offset=0&gender=1&generation=1";
    [AFRequdstAndLoad dataURLStr:str datahand:^(id object) {
        self.cookArr = [NSMutableArray array];
        self.cookMoreArr = [NSMutableArray array];
        NSDictionary *dic = [object objectForKey:@"data"];
        NSDictionary *dic2 = [dic objectForKey:@"paging"];
        NSString *next_url = [dic2 objectForKey:@"next_url"];
        [self.cookMoreArr addObject:next_url];
        NSArray *arr = [dic objectForKey:@"items"];
        for (NSDictionary *dic1 in arr) {
            TeachingData *selectData = [[TeachingData alloc] init];
            [selectData setValuesForKeysWithDictionary:dic1];
            [self.cookArr addObject:selectData];
        }
        [self.cookCell.tabelView.header endRefreshing];
        [self.collectionview reloadData];
    }];
}

- (void)CookHandlMoreData:(CookCollectionViewCell *)cell
{
    NSString *next_url = [self.cookMoreArr lastObject];
    if ([next_url isKindOfClass:[NSNull class]]) {
        [cell.tabelView.footer endRefreshing];
    }else{
    [AFRequdstAndLoad dataURLStr:next_url datahand:^(id object) {
        if (object) {
            [cell.tabelView.footer endRefreshing];
        }
        NSDictionary *dic = [object objectForKey:@"data"];
        NSDictionary *dic2 = [dic objectForKey:@"paging"];
        NSString *next_url = [dic2 objectForKey:@"next_url"];

        [self.cookMoreArr addObject:next_url];
        NSArray *arr = [dic objectForKey:@"items"];
        for (NSDictionary *dic1 in arr) {
            TeachingData *selectData = [[TeachingData alloc] init];
            [selectData setValuesForKeysWithDictionary:dic1];
            [self.cookArr addObject:selectData];
        }
        [self.collectionview reloadData];
        
    }];
    }
}
- (void)leftAction
{
    
    AppDelegate *appD = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    if (appD.leftSlideVC.closed) {
        [appD.leftSlideVC openLeftView];
    }else{
        [appD.leftSlideVC closeLeftView];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
